﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP20.ViewModels
{
    public class HeightCheckViewModel : BaseViewModel
    {


        public HeightCheckViewModel(IRegionManager regionManager) : base(regionManager)
        {

            InitParam();
            //开启定时器任务
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            dispatcherTimer.Tick += OnTick;
            dispatcherTimer.Start();
        }

        private void InitParam()
        {
            ST2CalibrationValue = TestHigh_Global.testValues[0].CurrentValue;
            ST2ErrorRange = TestHigh_Global.testValues[0].ErrorRange;

            ST5CalibrationValue = TestHigh_Global.testValues[1].CurrentValue;
            ST5ErrorRange = TestHigh_Global.testValues[1].ErrorRange;

            ST13CalibrationValue = TestHigh_Global.testValues[2].CurrentValue;
            ST13ErrorRange = TestHigh_Global.testValues[2].ErrorRange;
        }

        private void OnTick(object? sender, EventArgs e)
        {
            ST2CurrentValue = OtherDevicePLCToPC_Global.testDatas[0].CurrentValue;
            ST2ResultValue = OtherDevicePLCToPC_Global.testDatas[0].ResultValue;
            ST5CurrentValue = OtherDevicePLCToPC_Global.testDatas[1].CurrentValue;
            ST5ResultValue = OtherDevicePLCToPC_Global.testDatas[1].ResultValue;
            ST13CurrentValue = OtherDevicePLCToPC_Global.testDatas[2].CurrentValue;
            ST13ResultValue = OtherDevicePLCToPC_Global.testDatas[2].ResultValue;
        }

        #region 事件
        private DelegateCommand _ST2CheckDownCmd;
        public DelegateCommand ST2CheckDownCmd =>
            _ST2CheckDownCmd ?? (_ST2CheckDownCmd = new DelegateCommand(ExecuteST2CheckDownCmd));

        void ExecuteST2CheckDownCmd()
        {
            OtherDevicePCToPLC_Global.ST2HightBoolArr[0] = true;
        }

        private DelegateCommand _ST2CheckUpCmd;
        public DelegateCommand ST2CheckUpCmd =>
            _ST2CheckUpCmd ?? (_ST2CheckUpCmd = new DelegateCommand(ExecuteST2CheckUpCmd));

        void ExecuteST2CheckUpCmd()
        {
            OtherDevicePCToPLC_Global.ST2HightBoolArr[0] = false;

        }

        private DelegateCommand _ST2CalibrationDownCmd;
        public DelegateCommand ST2CalibrationDownCmd =>
            _ST2CalibrationDownCmd ?? (_ST2CalibrationDownCmd = new DelegateCommand(ExecuteST2CalibrationDownCmd));

        void ExecuteST2CalibrationDownCmd()
        {
            OtherDevicePCToPLC_Global.ST2HightBoolArr[1] = true;

        }

        private DelegateCommand _ST2CalibrationUpCmd;
        public DelegateCommand ST2CalibrationUpCmd =>
            _ST2CalibrationUpCmd ?? (_ST2CalibrationUpCmd = new DelegateCommand(ExecuteST2CalibrationUpCmd));

        void ExecuteST2CalibrationUpCmd()
        {
            OtherDevicePCToPLC_Global.ST2HightBoolArr[1] = false;

        }

        private DelegateCommand _ST2TestDownCmd;
        public DelegateCommand ST2TestDownCmd =>
            _ST2TestDownCmd ?? (_ST2TestDownCmd = new DelegateCommand(ExecuteST2TestDownCmd));

        void ExecuteST2TestDownCmd()
        {
            OtherDevicePCToPLC_Global.ST2HightBoolArr[2] = true;

        }
        private DelegateCommand _ST2TestUpCmd;
        public DelegateCommand ST2TestUpCmd =>
            _ST2TestUpCmd ?? (_ST2TestUpCmd = new DelegateCommand(ExecuteST2TestUpCmd));

        void ExecuteST2TestUpCmd()
        {
            OtherDevicePCToPLC_Global.ST2HightBoolArr[2] = false;

        }


        private DelegateCommand _ST5CheckDownCmd;
        public DelegateCommand ST5CheckDownCmd =>
            _ST5CheckDownCmd ?? (_ST5CheckDownCmd = new DelegateCommand(ExecuteST5CheckDownCmd));

        void ExecuteST5CheckDownCmd()
        {
            OtherDevicePCToPLC_Global.ST5HightBoolArr[0] = true;

        }

        private DelegateCommand _ST5CheckUpCmd;
        public DelegateCommand ST5CheckUpCmd =>
            _ST5CheckUpCmd ?? (_ST5CheckUpCmd = new DelegateCommand(ExecuteST5CheckUpCmd));

        void ExecuteST5CheckUpCmd()
        {
            OtherDevicePCToPLC_Global.ST5HightBoolArr[0] = false;

        }

        private DelegateCommand _ST5CalibrationDownCmd;
        public DelegateCommand ST5CalibrationDownCmd =>
            _ST5CalibrationDownCmd ?? (_ST5CalibrationDownCmd = new DelegateCommand(ExecuteST5CalibrationDownCmd));

        void ExecuteST5CalibrationDownCmd()
        {
            OtherDevicePCToPLC_Global.ST5HightBoolArr[1] = true;

        }

        private DelegateCommand _ST5CalibrationUpCmd;
        public DelegateCommand ST5CalibrationUpCmd =>
            _ST5CalibrationUpCmd ?? (_ST5CalibrationUpCmd = new DelegateCommand(ExecuteST5CalibrationUpCmd));

        void ExecuteST5CalibrationUpCmd()
        {
            OtherDevicePCToPLC_Global.ST5HightBoolArr[1] = false;
        }

        private DelegateCommand _ST5TestDownCmd;
        public DelegateCommand ST5TestDownCmd =>
            _ST5TestDownCmd ?? (_ST5TestDownCmd = new DelegateCommand(ExecuteST5TestDownCmd));

        void ExecuteST5TestDownCmd()
        {
            OtherDevicePCToPLC_Global.ST5HightBoolArr[2] = true;

        }
        private DelegateCommand _ST5TestUpCmd;
        public DelegateCommand ST5TestUpCmd =>
            _ST5TestUpCmd ?? (_ST5TestUpCmd = new DelegateCommand(ExecuteST5TestUpCmd));

        void ExecuteST5TestUpCmd()
        {
            OtherDevicePCToPLC_Global.ST5HightBoolArr[2] = false;

        }

        private DelegateCommand _ST13CheckDownCmd;
        public DelegateCommand ST13CheckDownCmd =>
            _ST13CheckDownCmd ?? (_ST13CheckDownCmd = new DelegateCommand(ExecuteST13CheckDownCmd));

        void ExecuteST13CheckDownCmd()
        {
            OtherDevicePCToPLC_Global.ST13HightBoolArr[0] = true;

        }

        private DelegateCommand _ST13CheckUpCmd;
        public DelegateCommand ST13CheckUpCmd =>
            _ST13CheckUpCmd ?? (_ST13CheckUpCmd = new DelegateCommand(ExecuteST13CheckUpCmd));

        void ExecuteST13CheckUpCmd()
        {
            OtherDevicePCToPLC_Global.ST13HightBoolArr[0] = false;

        }

        private DelegateCommand _ST13CalibrationDownCmd;
        public DelegateCommand ST13CalibrationDownCmd =>
            _ST13CalibrationDownCmd ?? (_ST13CalibrationDownCmd = new DelegateCommand(ExecuteST13CalibrationDownCmd));

        void ExecuteST13CalibrationDownCmd()
        {
            OtherDevicePCToPLC_Global.ST13HightBoolArr[1] = true;

        }

        private DelegateCommand _ST13CalibrationUpCmd;
        public DelegateCommand ST13CalibrationUpCmd =>
            _ST13CalibrationUpCmd ?? (_ST13CalibrationUpCmd = new DelegateCommand(ExecuteST13CalibrationUpCmd));

        void ExecuteST13CalibrationUpCmd()
        {
            OtherDevicePCToPLC_Global.ST13HightBoolArr[1] = false;

        }

        private DelegateCommand _ST13TestDownCmd;
        public DelegateCommand ST13TestDownCmd =>
            _ST13TestDownCmd ?? (_ST13TestDownCmd = new DelegateCommand(ExecuteST13TestDownCmd));

        void ExecuteST13TestDownCmd()
        {
            OtherDevicePCToPLC_Global.ST13HightBoolArr[2] = true;

        }
        private DelegateCommand _ST13TestUpCmd;
        public DelegateCommand ST13TestUpCmd =>
            _ST13TestUpCmd ?? (_ST13TestUpCmd = new DelegateCommand(ExecuteST13TestUpCmd));

        void ExecuteST13TestUpCmd()
        {
            OtherDevicePCToPLC_Global.ST13HightBoolArr[2] = false;

        }


        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {

                case "ST2CalibrationValue":
                    TestHigh_Global.testValues[0].CurrentValue = ST2CalibrationValue;
                    break;
                case "ST2ErrorRange":
                    TestHigh_Global.testValues[0].ErrorRange = ST2ErrorRange;
                    break;
                case "ST5CalibrationValue":
                    TestHigh_Global.testValues[1].CurrentValue= ST5CalibrationValue ;
                    break;
                case "ST5ErrorRange":
                    TestHigh_Global.testValues[1].ErrorRange = ST5ErrorRange;
                    break;
                case "ST13CalibrationValue":

                    TestHigh_Global.testValues[2].CurrentValue = ST13CalibrationValue;
                    break;
                case "ST13ErrorRange":
                    TestHigh_Global.testValues[2].ErrorRange = ST13ErrorRange;
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region 属性


        private float _ST2CalibrationValue;
        public float ST2CalibrationValue
        {
            get { return _ST2CalibrationValue; }
            set { SetProperty(ref _ST2CalibrationValue, value); }
        }

        private float _ST2ErrorRange;
        public float ST2ErrorRange
        {
            get { return _ST2ErrorRange; }
            set { SetProperty(ref _ST2ErrorRange, value); }
        }

        private float _ST2CurrentValue;
        public float ST2CurrentValue
        {
            get { return _ST2CurrentValue; }
            set { SetProperty(ref _ST2CurrentValue, value); }
        }

        private float _ST2ResultValue;
        public float ST2ResultValue
        {
            get { return _ST2ResultValue; }
            set { SetProperty(ref _ST2ResultValue, value); }
        }



        private float _ST5CalibrationValue;
        public float ST5CalibrationValue
        {
            get { return _ST5CalibrationValue; }
            set { SetProperty(ref _ST5CalibrationValue, value); }
        }

        private float _ST5ErrorRange;
        public float ST5ErrorRange
        {
            get { return _ST5ErrorRange; }
            set { SetProperty(ref _ST5ErrorRange, value); }
        }

        private float _ST5CurrentValue;
        public float ST5CurrentValue
        {
            get { return _ST5CurrentValue; }
            set { SetProperty(ref _ST5CurrentValue, value); }
        }

        private float _ST5ResultValue;
        public float ST5ResultValue
        {
            get { return _ST5ResultValue; }
            set { SetProperty(ref _ST5ResultValue, value); }
        }



        private float _ST13CalibrationValue;
        public float ST13CalibrationValue
        {
            get { return _ST13CalibrationValue; }
            set { SetProperty(ref _ST13CalibrationValue, value); }
        }

        private float _ST13ErrorRange;
        public float ST13ErrorRange
        {
            get { return _ST13ErrorRange; }
            set { SetProperty(ref _ST13ErrorRange, value); }
        }

        private float _ST13CurrentValue;
        public float ST13CurrentValue
        {
            get { return _ST13CurrentValue; }
            set { SetProperty(ref _ST13CurrentValue, value); }
        }

        private float _ST13ResultValue;
        public float ST13ResultValue
        {
            get { return _ST13ResultValue; }
            set { SetProperty(ref _ST13ResultValue, value); }
        }
        #endregion

    }
}
